package com.kewill.jira.util;

/**
 * <p>Title:  HtmlUtil </p>
 * <p>Description:  HtmlUtil </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: IPACS e-Solutions (S) Pte Ltd</p>
 * Date: 2004-1-30
 * Time: 14:49:16
 *
 * @author yuanzd
 * @version 1.0
 */
public class HtmlUtil {

    /**
     * convert s to html string.replace"<",">","&",";" symbol to"&lt", "&gt"
     */
    public static String encodeHtml(String value) {
        if (value == null) {
            return (null);
        }
        char content[] = new char[value.length()];
        value.getChars(0, value.length(), content, 0);
        StringBuffer result = new StringBuffer(content.length + 50);
        for (int i = 0; i < content.length; i++) {
            switch (content[i]) {
                case '<':
                    result.append("&lt;");
                    break;
                case '>':
                    result.append("&gt;");
                    break;
                case '&':
                    result.append("&amp;");
                    break;
                case '"':
                    result.append("&quot;");
                    break;
                case '\'':
                    result.append("&#39;");
                    break;
                case '\n':
                    result.append("<br>");
                    break;
                default:
                    result.append(content[i]);
            }
        }
        return (result.toString());
    }
}
